﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using CommDll;

namespace HospitalMedicineTraceability
{
    /// <summary>
    /// ClassName:frmListInfoSelect
    /// Version:1.0
    /// Date:2022-11-23
    /// Author:seanouyang
    /// </summary>
    /// <remarks>
    /// 本类是一WinForm 窗体,本窗体主要为列表信息选定确定
    /// </remarks>    
    public partial class frmListInfoSelect : DevComponents.DotNetBar.OfficeForm
    {
        #region 01.自定义属性
        public string m_strInfoKind = ""; // Supplier:配企确定,StockPlace:库房信息,BatchCode:批号 
        public DataTable m_dt = null;   // 数据
        public string  m_strInfo = "";   // 返回选择信息
        #endregion

        public frmListInfoSelect()
        {
            InitializeComponent(); 
        }
        #region 01 自定义方法
        /// <summary>
        /// 初始化库房信息
        /// </summary>
        private void _init()
        {
            string strSql = "";
            switch (m_strInfoKind)
            {
                case "Supplier":
                    lblTitle.Text = "请确定配送企业";
                    this.Text = lblTitle.Text;                   
                    break;
                case "Pharmacy":
                    lblTitle.Text = "请确定门诊药房";
                    this.Text = lblTitle.Text;
                    strSql = @"select PharmacyName + '|' + PharmacyCode  as Name from TH_PharmacyStockOut where PharmacyName like '%诊%' group by PharmacyCode,PharmacyName order by PharmacyCode";
                    m_dt = AppInfo._openSql_DataTable(strSql);
                    break;
                case "Pharmacy1":
                    lblTitle.Text = "请确定住院药房";
                    this.Text = lblTitle.Text;
                    strSql = @"select PharmacyName + '|' + PharmacyCode  as Name from TH_Pharmacy1StockOut where PharmacyName not like '%诊%' group by PharmacyCode,PharmacyName order by PharmacyCode";
                    m_dt = AppInfo._openSql_DataTable(strSql);
                    break;
                case "Warehouse":
                    lblTitle.Text = "请确定药库";
                    this.Text = lblTitle.Text;
                    strSql = @"select WarehouseName + '|' + WarehouseCode  as Name from TH_WarehouseStockOut group by WarehouseCode,WarehouseName order by WarehouseCode";
                    m_dt = AppInfo._openSql_DataTable(strSql);
                    break;
                case "StockPlace":
                    lblTitle.Text = "库房盘点-库房确定";
                    this.Text = lblTitle.Text;
                    strSql = @"select Name + '|' + Code + '|' + Kind  as StockPlace
                        from
                        (
                        select Code,Name,'药库' as Kind from TH_Warehouse
                        Union all
                        select Code,Name,'药房' as Kind from TH_Pharmacy
                        )A order by Kind,Code";
                    strSql = string.Format(strSql, AppInfo.m_UserInfo.m_strDeptCode);
                    m_dt = AppInfo._openSql_DataTable(strSql);
                    break;
                case "BatchCode":
                    lblTitle.Text = "请确定商品批号";
                    this.Text = lblTitle.Text;
                    break;
                default:
                    break;
            }
            // 初始化信息
            if (m_dt != null)
            {
                foreach (DataRow dr in m_dt.Rows)
                {
                    lbInfo.Items.Add(dr[0].ToString());
                }
            }
        }
        #endregion

        #region 02.系统事件方法
        private void frmSupplierConfirm_Load(object sender, EventArgs e)
        {
            _init();     
        }

        private void lbInfo_MeasureItem(object sender, MeasureItemEventArgs e)
        {
            this.lbInfo.ItemHeight = 22;
        }

        private void lbInfo_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();
            e.DrawFocusRectangle();
            e.Graphics.DrawString(lbInfo.Items[e.Index].ToString(), e.Font, new SolidBrush(Color.Black), e.Bounds);
        }

        private void lbInfo_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            btnSave_Click(null,null);
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (lbInfo.SelectedIndex >= 0)
            {
                m_strInfo = lbInfo.Text;
                DialogResult = DialogResult.OK;
            }
        }

        private void btnReturn_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion
    }
}